﻿using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

#nullable disable

namespace ms.userlable.read.Models
{
    public partial class userslabelprintContext : DbContext
    {
        public userslabelprintContext()
        {
        }

        public userslabelprintContext(DbContextOptions<userslabelprintContext> options)
            : base(options)
        {
        }

        public virtual DbSet<CustomHistory> CustomHistories { get; set; }
        public virtual DbSet<DalPrinter> DalPrinters { get; set; }
        public virtual DbSet<DalPrinter1> DalPrinters1 { get; set; }
        public virtual DbSet<Person> People { get; set; }
        public virtual DbSet<PrintHistory> PrintHistories { get; set; }
        public virtual DbSet<PrintQuotum> PrintQuota { get; set; }
        public virtual DbSet<RemainingQuotum> RemainingQuota { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
                optionsBuilder.UseSqlite("data source=C:\\Users\\YANG.LEI\\AppData\\Roaming\\UsersLabelPrint\\userslabelprint.db;foreign keys=true;");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<CustomHistory>(entity =>
            {
                entity.Property(e => e.Id).ValueGeneratedNever();

                entity.Property(e => e.Context).HasColumnType("nvarchar");

                entity.Property(e => e.CreateDate)
                    .IsRequired()
                    .HasColumnType("datetime");

                entity.Property(e => e.Hash).HasColumnType("nvarchar");
            });

            modelBuilder.Entity<DalPrinter>(entity =>
            {
                entity.Property(e => e.Id).ValueGeneratedNever();

                entity.Property(e => e.PrinterName).HasColumnType("nvarchar (255)");
            });

            modelBuilder.Entity<DalPrinter1>(entity =>
            {
                entity.ToTable("DalPrinter");

                entity.Property(e => e.Id).ValueGeneratedNever();

                entity.Property(e => e.FullNameWithoutTopDir).HasColumnType("nvarchar (255)");
            });

            modelBuilder.Entity<Person>(entity =>
            {
                entity.ToTable("Person");

                entity.Property(e => e.Id).ValueGeneratedNever();

                entity.Property(e => e.PasswordHash).HasColumnType("nvarchar (50)");

                entity.Property(e => e.UserName)
                    .IsRequired()
                    .HasColumnType("nvarchar (50)");
            });

            modelBuilder.Entity<PrintHistory>(entity =>
            {
                entity.ToTable("PrintHistory");

                entity.HasIndex(e => e.DalPrinterId, "IX_PrintHistory_DalPrinterId");

                entity.HasIndex(e => e.LabelId, "IX_PrintHistory_LabelId");

                entity.HasIndex(e => e.PersonId, "IX_PrintHistory_PersonId");

                entity.Property(e => e.Id).ValueGeneratedNever();

                entity.Property(e => e.BatchNumber).HasColumnType("nvarchar");

                entity.Property(e => e.DalPrinterId).HasColumnType("int");

                entity.Property(e => e.LabelDate)
                    .IsRequired()
                    .HasColumnType("datetime");

                entity.Property(e => e.LabelId).HasColumnType("int");

                entity.Property(e => e.PersonId).HasColumnType("int");

                entity.Property(e => e.PrintCount).HasColumnType("int");

                entity.Property(e => e.PrintDate)
                    .IsRequired()
                    .HasColumnType("datetime");

                entity.Property(e => e.Sn).HasColumnType("int");

                entity.HasOne(d => d.DalPrinter)
                    .WithMany(p => p.PrintHistories)
                    .HasForeignKey(d => d.DalPrinterId);

                entity.HasOne(d => d.Label)
                    .WithMany(p => p.PrintHistories)
                    .HasForeignKey(d => d.LabelId);

                entity.HasOne(d => d.Person)
                    .WithMany(p => p.PrintHistories)
                    .HasForeignKey(d => d.PersonId);
            });

            modelBuilder.Entity<PrintQuotum>(entity =>
            {
                entity.Property(e => e.Id).ValueGeneratedNever();

                entity.Property(e => e.LicenseGuid).HasColumnType("nvarchar (50)");

                entity.Property(e => e.LicenseGuidEncrypted).HasColumnType("nvarchar");

                entity.Property(e => e.Quota).HasColumnType("int");

                entity.Property(e => e.QuotaEncrypted).HasColumnType("nvarchar");
            });

            modelBuilder.Entity<RemainingQuotum>(entity =>
            {
                entity.Property(e => e.Id).ValueGeneratedNever();

                entity.Property(e => e.Remaining).HasColumnType("int");

                entity.Property(e => e.RemainingEncrypted).HasColumnType("nvarchar");

                entity.Property(e => e.Total).HasColumnType("int");

                entity.Property(e => e.TotalEncrypted).HasColumnType("nvarchar");
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
